/****************************************************
	文件：TimerService.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2021/1/10 12:48:20
	功能：计时任务 服务
*****************************************************/

using System;
using System.Collections.Generic;
using HTFW.Consts;
using HTFW.Logger;
using HTFW.Utility.Global;

namespace HTFW.Core
{
    [Obsolete("请使用 TimerContext")]
    public class TimerService : Singleton<TimerService>, IService, ITimerUpdate
    {
        //--------------------  字段  -----------------//

        #region 字段

        private HTTimer mHTTimer;

        #endregion


        //--------------------  生命周期  -----------------//

        #region 生命周期

        /// <summary>
        /// 初始化计时器
        /// </summary>
        /// <param name="args"></param>
        public void Init(params object[] args)
        {
            mHTTimer = TimerFactory.Instance.GetTimer();

            HLog.Debug("HTTimer init done.");
        }

        public void Dispose()
        {
            mHTTimer.Dispose();
        }

        public void OnTimerUpdate()
        {
            mHTTimer.Update();
        }

        #endregion


        //--------------------  计时任务  -----------------//

        #region 计时任务

        /// <summary>
        /// 添加计时任务
        /// 返回此任务的全局ID
        /// </summary>
        /// <param name="callBack">计时任务回调</param>
        /// <param name="delayTime">延迟时间</param>
        /// <param name="timeUnit">时间单位</param>
        /// <param name="loopCount">循环次数</param>
        /// <returns></returns>
        public int AddTimeTask(Action<int> callBack, double delayTime, TimeUnit timeUnit = TimeUnit.MilliSecond,
            int loopCount = 1)
        {
            return mHTTimer.AddTimeTask(callBack, delayTime, timeUnit, loopCount);
        }

        /// <summary>
        /// 移除计时任务
        /// </summary>
        /// <param name="tID">任务的全局ID</param>
        public void RemoveTimeTask(int tID)
        {
            mHTTimer.RemoveTimeTask(tID);
        }

        /// <summary>
        /// 替换计时任务
        /// 返回bool（是否替换成功）
        /// </summary>
        /// <param name="tID">待替换任务的全局ID</param>
        /// <param name="callBack">计时任务回调</param>
        /// <param name="delayTime">延迟时间</param>
        /// <param name="timeUnit">时间单位</param>
        /// <param name="loopCount">循环次数</param>
        /// <returns></returns>
        public bool ReplaceTimeTask(int tID, Action<int> callBack, double delayTime,
            TimeUnit timeUnit = TimeUnit.MilliSecond, int loopCount = 1)
        {
            return mHTTimer.ReplaceTimeTask(tID, callBack, delayTime, timeUnit, loopCount);
        }

        #endregion


        //--------------------  帧任务  -----------------//

        #region 帧任务

        /// <summary>
        /// 添加帧任务
        /// 返回此任务的全局ID
        /// </summary>
        /// <param name="callBack">帧任务回调</param>
        /// <param name="delayFrame">延迟帧</param>
        /// <param name="loopCount">循环次数</param>
        /// <returns></returns>
        public int AddFrameTask(Action<int> callBack, int delayFrame, int loopCount = 1)
        {
            return mHTTimer.AddFrameTask(callBack, delayFrame, loopCount);
        }

        /// <summary>
        /// 移除帧任务
        /// </summary>
        /// <param name="tID">任务的全局ID</param>
        public void RemoveFrameTask(int tID)
        {
            mHTTimer.RemoveFrameTask(tID);
        }

        /// <summary>
        /// 替换帧任务
        /// 返回bool（是否替换成功）
        /// </summary>
        /// <param name="tID">待替换任务的全局ID</param>
        /// <param name="callBack">帧任务回调</param>
        /// <param name="delayFrame">延迟帧</param>
        /// <param name="loopCount">循环次数</param>
        /// <returns></returns>
        public bool ReplaceFrameTask(int tID, Action<int> callBack, int delayFrame, int loopCount = 1)
        {
            return mHTTimer.ReplaceFrameTask(tID, callBack, delayFrame, loopCount);
        }

        #endregion
    }
}